package cn.bdqn.text;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 懒汉单例模式
 * 404: 请求路径不存在
 * 405: 请求方式错误，没有对应的doXXX方法
 * 500: 后台错误
 */
@WebServlet("/test.do")
public class TestServlet extends HttpServlet {

    @Override
    public void init() throws ServletException {
        System.out.println("Servlet的init初始化方法，只创建时调用一次");
    }

    @Override
    public void destroy() {
        System.out.println("Servlet的destroy销毁方法，只在Tomcat移出应用时调用一次");
    }


    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("Servlet的service服务方法，每次请求都会调用一次:"+this);
        super.service(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("test.do");
  //      String str = null;
  //      System.out.println(str.toString());
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }
}
